 import request from "@/config/axiosConfig.js"
 import {updateRequestType} from "@/types/kb.ts";
 import axios from "axios";

export const createKnowledge = () => {
    return request({
        url: '/knowledge/create',
        method: 'post',
        timeout: 20000
    })
}

export const insertChunk = (knowledgeId:string) => {
    return request({
        url: '/knowledge/insertChunk',
        method: 'post',
        timeout: 20000,
        data: { knowledgeId: knowledgeId }
    })
}

export const getKnowledges = () => {
    return request({
        url: '/knowledge/getKnowledges',
        method: 'get',
        timeout: 20000
    })
}

export const getChunks = (knowledgeId:string) => {
    return request({
        url: '/knowledge/getChunks',
        method: 'get',
        timeout: 20000,
        params: { knowledgeId: knowledgeId }
    })
}

export const updateChunk = (updateChunkRequest:updateRequestType) => {
    return request({
        url: '/knowledge/updateChunk',
        method: 'put',
        timeout: 20000,
        data: updateChunkRequest
    })
}

 export const uploadFile = (file,knowledgeId) => {
    console.log(file)
     const formData = new FormData();
     formData.append('file', file);

     // return axios.post(`localhost:8080/api/upload`, formData, {
     //     headers: {
     //         'Content-Type': 'multipart/form-data'
     //     },
     //     timeout: 20000
     // });
     return request({
         url: '/file/upload',
         method: 'post',
         timeout: 40000,
         params: { knowledgeId: knowledgeId },
         data: formData
     })

 };
